package com.example.entity.exception;

import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author yudong
 * @Date 2023/3/1 17:47
 * @description：自定义全局异常
 */
@RestControllerAdvice
public class MyExceptionHandler {

    @ExceptionHandler(Exception.class)
    public JSONObject customException(Exception e) {
        JSONObject json=new JSONObject();
        json.put("code",-1);
        json.put("msg",e.toString());
        return json;
    }
}
